package at.fhj.itm11.forum.beans.stubs;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import org.primefaces.model.UploadedFile;

import at.fhj.itm11.forum.service.PostService;
import at.fhj.itm11.forum.service.dtos.PostDTO;
import at.fhj.itm11.forum.service.dtos.TopicDTO;
import at.fhj.itm11.forum.service.dtos.UserDTO;

public class PostServiceStub implements PostService {
	
	public static final String TITLE_THROW_EXCEPTION = "exception";
	
	@Override
	public List<PostDTO> getPostsByTopicId(long topicId) {
		List<PostDTO> postsList = null;
		
		if(topicId == TopicServiceStub.EXISTING_ID_WITH_POSTS) {
			postsList = new LinkedList<PostDTO>();
			postsList.add(new PostDTO());
		} else if (topicId == TopicServiceStub.EXISTING_ID_WITHOUT_POSTS) {
			postsList = new LinkedList<PostDTO>();
		}
		
		return postsList;
	}

	@Override
	public long addPost(String title, String text, UploadedFile image,
			UploadedFile video, TopicDTO topic, UserDTO user)
			throws IllegalArgumentException {
		
		if (TITLE_THROW_EXCEPTION.equals(title)) {
			throw new IllegalArgumentException();
		}
		
		if (title == null || "".equals(title)) {
			throw new IllegalArgumentException(EXCEPTION_TITLE_EMPTY);
		}

		if (text == null || "".equals(text)) {
			throw new IllegalArgumentException(EXCEPTION_TEXT_EMPTY);
		}

		if (image == null) {
			throw new IllegalArgumentException(EXCEPTION_ONLY_IMAGES);
		}

		if (video == null) {
			throw new IllegalArgumentException(EXCEPTION_ONLY_VIDEOS);
		}
		
		return 0;
	}

	@Override
	public PostDTO findById(long id) {
		PostDTO dto = new PostDTO();
		dto.setId(id);
		dto.setDate(new Date());

		if (id == 1L) {
			dto.setImage(new byte[] { 1, 2, 3, 4 });
		}

		if (id == 2L) {
			dto.setVideo(new byte[] { 1, 2, 3, 4 });
		}

		return dto;
	}

}
